<template>
	<view class="home-monitor-list" v-if="isLoad">

		<fixed>
			<view class="fill-base pt-big pb-big pl-md pr-md">
				<search @input="toSearch" type="input" :padding="0" :radius="70" placeholder="搜索监控名称"></search>
			</view>
		</fixed>

		<view class="flex-warp ml-md mr-md">
			<view @tap.stop="goDetail(index)" class="monitor-item rel fill-base box-shadow radius-16"
				:class="[{'mr-md':index%2==0}]" v-for="(item,index) in list.data" :key="index">
				<view class="live-item flex-center abs">
					<image mode="aspectFill" lazy-load class="live-img" src="/static/image/home/live.png"></image>
					<view class="f-icontext c-base">LIVE</view>
				</view>
				<view class="view-item flex-center abs c-base">
					<i class="iconfont icon-chakan mr-sm"></i>
					<view class="f-icontext">{{item.iv || 0}}</view>
				</view>
				<image mode="aspectFill" lazy-load class="cover" :src="item.cover"></image>
				<view class="content">
					<view class="f-paragraph c-title ellipsis">{{item.title}}</view>
					<view class="flex-y-center f-caption c-caption"><i class="iconfont icon-dingwei mr-sm"></i>
						<view class="max-300 ellipsis">{{item.address}}</view>
					</view>
				</view>
			</view>
		</view>
		<load-more :noMore="list.current_page>=list.last_page&&list.data.length>0" :loading="loading" v-if="loading">
		</load-more>
		<abnor v-if="!loading&&list.data.length<=0&&list.current_page==1"></abnor>
		<view class="space-footer"></view>
	</view>
</template>

<script>
	import {
		mapState,
		mapActions,
		mapMutations
	} from "vuex"
	export default {
		components: {},
		data() {
			return {
				isLoad: false,
				options: {},
				rankInd: 0,
				rankList: [{
					id: 1,
					title: '综合排序'
				}, {
					id: 2,
					title: '距离最近'
				}, {
					id: 3,
					title: '观看最多'
				}],
				activeIndex: 0,
				tabList: [],
				param: {
					page: 1,
				},
				list: {
					data: []
				},
				loading: true,
				lockTap: false,
			}
		},
		computed: mapState({
			primaryColor: state => state.config.configInfo.primaryColor,
			subColor: state => state.config.configInfo.subColor,
			userInfo: state => state.user.userInfo,
			location: state => state.user.location,
		}),
		async onLoad(options) {
			this.$util.showLoading()
			this.options = options
			await this.initIndex()
			this.isLoad = true
		},
		onPullDownRefresh() {
			// #ifndef APP-PLUS
			uni.showNavigationBarLoading()
			// #endif
			this.initRefresh()
			uni.stopPullDownRefresh()
		},
		onReachBottom() {
			if (this.list.current_page >= this.list.last_page || this.loading) return
			this.param.page = this.param.page + 1
			this.loading = true
			this.getList()
		},
		methods: {
			...mapActions(['getConfigInfo']),
			...mapMutations(['updateUserItem']),
			async initIndex() {
				this.getList()
			},
			initRefresh() {
				this.param.page = 1
				this.initIndex()
			},
			toSearch(val) {
				this.loading = true
				this.param.page = 1
				this.param.title = val
				this.getList()
			},
			handerTabChange(index, type) {
				this[type] = index
				if (type == 'rankInd') {
					this.$refs.rank_item.close()
				}
				this.$util.showLoading()
				this.param.page = 1
				this.list.data = []
				this.getList()
			},
			async getList() {
				let {
					list: oldList,
					param,
				} = this
				let {
					id = 0,
				} = this.options
				param.farmer_id = id
				let newList = await this.$api.home.monitorList(param)
				if (this.param.page == 1) {
					this.list = newList
				} else {
					newList.data = oldList.data.concat(newList.data)
					this.list = newList
				}
				this.loading = false
				this.$util.hideAll()
			},
			async goDetail(index) {
				let {
					id
				} = this.list.data[index]
				let url = `/home/pages/monitor/detail?id=${id}`
				this.$util.goUrl({
					url
				})
			}
		}
	}
</script>


<style lang="scss">
	.home-monitor-list {
		.monitor-item {
			width: 345rpx;
			margin-top: 24rpx;

			.live-item {
				top: 10rpx;
				left: 10rpx;
				width: 109rpx;
				height: 38rpx;
				background: rgba(0, 0, 0, 0.3);
				border-radius: 18rpx;

				.live-img {
					top: 0;
					width: 38rpx;
					height: 38rpx;
				}

				.f-icontext {
					margin-left: 10rpx;
					width: 61rpx;
				}
			}

			.view-item {
				top: 0;
				right: 0;
				width: 137rpx;
				height: 51rpx;
				background: rgba(0, 0, 0, 0.3);
				border-radius: 0 15rpx 0 0;
			}

			.cover {
				width: 345rpx;
				height: 190rpx;
				border-radius: 15rpx 15rpx 0 0;
			}

			.content {
				padding: 24rpx;

				.iconfont {
					font-size: 26rpx;
				}
			}
		}

	}
</style>
